﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BooksManagermentSystem
{
    public partial class login_form : Form
    {
        public login_form()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //获取前端文本框中的值
            string uname = textBox1.Text.Trim();

            //非空验证
            if(uname == "")
            {
                MessageBox.Show("请输入用户名！");
                textBox1.Focus();
                return;
            }

            string pwd =textBox2.Text.Trim();
            if(pwd == "")
            {
                MessageBox.Show("请输入密码！");
                textBox2.Focus();
                return;
            }

            try
            {
                //身份验证
                if (radioButton1.Checked)
                {
                    if (DBhelper.checkStu(uname, pwd))
                    {
                        StudentMain_form sm = new StudentMain_form();
                        //传学号
                        sm.Tag = uname;
                        sm.StartPosition= FormStartPosition.CenterParent;
                        sm.Show();
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码不正确！");
                        textBox1.Focus();
                        return;
                    }
                }
                else
                {
                    if (DBhelper.checkAdmin(uname, pwd))
                    {
                        AdminMain_form am = new AdminMain_form();
                        am.Tag = uname;
                        am.StartPosition= FormStartPosition.CenterParent;
                        am.Show();
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码不正确！");
                        textBox1.Focus();
                        return;
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            this.Hide();
        }
    }
}
